package com.aoxin.controller.course.webCourse;

import com.aoxin.model.SlfUserAppraise;
import com.aoxin.service.inter.course.webCourse.UserAppraiseService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.EmptyUtil;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/web/userAppraise/")
public class UserAppraiseController {

    @Autowired
    UserAppraiseService userAppraiseService;

    /**
     * 新增用户备注
     * @param slfUserAppraise
     * @param res
     * @return
     */
    @RequestMapping("insertUserAppraise")
    @LogInfo(content = "用户评价",operateType = OperateType.INSERT)
    public AjaxRes insertUserAppraise(SlfUserAppraise slfUserAppraise,AjaxRes res){
        try {
            if(!EmptyUtil.objFieldsIsEmpty(slfUserAppraise)){
                Integer result = userAppraiseService.insertUserAppraise(slfUserAppraise);
                if(result != 0){
                    res.setFailMsg("insertUserAppraise success!");
                }else {
                    res.setFailMsg("insertUserAppraise Fail!");
                }
            }else {
                res.setFailMsg("slfUserAppraise is null");
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 删除用户备注
     * @param userAppraiseId
     * @param res
     * @return
     */
    @RequestMapping("deleteByuserAppraiseId")
    @LogInfo(content = "用户评价",operateType = OperateType.DELETE)
    public AjaxRes deleteByuserAppraiseId(Integer userAppraiseId,AjaxRes res){
        if(userAppraiseId != null){
            Integer result = userAppraiseService.deleteByAppraiseId(userAppraiseId);
            if(result != 0){
                res.setSucceedMsg("deleteUserAppraise success!");
            }else{
                res.setFailMsg("deleteUserAppraise Fail!");
            }
        }else {
            res.setFailMsg("userAppraiseId is null");
        }
        return res;
    }

    /**
     * 批量删除用户备注信息
     * @param userAppraiseIds
     * @param res
     * @return
     */
    @RequestMapping("deleteUserAppraise")
    @LogInfo(content = "用户评价",operateType = OperateType.DELETE)
    public AjaxRes deleteUserAppraise(@RequestParam("userAppraiseIds") List<Integer> userAppraiseIds, AjaxRes res){
        if(userAppraiseIds != null && userAppraiseIds.size() > 0){
            Integer result = userAppraiseService.deleteUserAppraise(userAppraiseIds);
            if(result != 0){
                res.setSucceedMsg("deleteUserAppraise success!");
            }else {
                res.setFailMsg("deleteUserAppraise Fail!");
            }
        }else {
            res.setFailMsg("userAppraiseIds is null");
        }
        return res;
    }


    /**
     * 查询用户备注
     * @param slfUserAppraise
     * @param res
     * @return
     */
    @RequestMapping("getUserAppraise")
    @LogInfo(content = "用户评价",operateType = OperateType.QUERY)
    public AjaxRes getUserAppraise(SlfUserAppraise slfUserAppraise, AjaxRes res){
        List<SlfUserAppraise> slfUserAppraisePageInfo = userAppraiseService.getUserAppraise(slfUserAppraise);
        res.setSucceed(slfUserAppraisePageInfo,"getUserAppraise success!");
        return res;
    }

    /**
     * 修改用户备注
     * @param slfUserAppraise
     * @param res
     * @return
     */
    @RequestMapping("updateUserAppraise")
    @LogInfo(content = "用户评价",operateType = OperateType.UPDATE)
    public AjaxRes updateUserAppraise(SlfUserAppraise slfUserAppraise,AjaxRes res){
        try {
            if(!EmptyUtil.objFieldsIsEmpty(slfUserAppraise)){
                Integer result = userAppraiseService.updateUserAppraise(slfUserAppraise);
                if(result != 0){
                    res.setSucceedMsg("updateUserAppraise success!");
                }else {
                    res.setFailMsg("updateUserAppraise Fail!");
                }
            }else {
                res.setFailMsg("slfUserAppraise is null");
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return res;
    }
}
